home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / COMMON.ZIP / MOUSE.TXT < prev    next >
Encoding:
Text File  |  1995-11-11  |  4.0 KB  |  190 lines

  1. /*
  2.  
  3.   an example of installing a mouse handler via int33
  4.  
  5.   Copyright 1995 Alexander J. Russell
  6.   Placed in the public domain.
  7.  
  8. */
  9.  
  10. short mouse_x, mouse_y;
  11. short mouse_present;
  12. short mouse_hidden=0;
  13. short button_stat=0;
  14. USHORT flags;
  15.  
  16.  
  17. /* the low level interrupt handler calls this */
  18. /* ---------------------- mouse_handler() ----------------- April 1,1993 */
  19. void far interrupt mouse_handler(void)
  20. {
  21.  
  22.    /* save info returned by mouse device driver */
  23.    asm   {
  24.          mov   flags,   ax
  25.          mov   mouse_x, cx
  26.          mov   mouse_y, dx
  27.          mov   button_stat, bx
  28.          }
  29.  
  30.  
  31.    /*
  32.  
  33.    add your code here to actually do something with the mouse info
  34.  
  35.    check flags for type of mouse event
  36.  
  37.  
  38.    */
  39. }
  40.  
  41.  
  42. /*
  43.  
  44.    the assembler function mouse_int() calls
  45.    mouse_event_func whenever the mouse moves, or a button
  46.    is pressed, or released. mouse_event_func points to mouse_handler
  47.    which ques up the mouse events, get_event can be used to read these
  48.    events.
  49.  
  50. */
  51.  
  52. /* is there a mouse, install int handlers */
  53. /* ---------------------- init_mouse() -------------------- April 1,1993 */
  54. short init_mouse(void)
  55. {
  56.    USHORT c_seg, c_off;
  57.  
  58.    asm   {
  59.          xor   ax, ax
  60.          int   033h
  61.  
  62.          /* note BX holds number of buttons, but we don't care */
  63.          mov   mouse_present, ax
  64.          }
  65.  
  66.    if ( mouse_present )
  67.       {
  68.       /* install our own handler */
  69.       mouse_event_func=mouse_handler; /* global func pointer */
  70.  
  71.       want_mouse_moves=0;
  72.  
  73.       /* install mouse_int as mouse handler, which will call
  74.          mouse_handler */
  75.  
  76.       c_seg=FP_SEG(mouse_int);
  77.       c_off=FP_OFF(mouse_int);
  78.       asm   {
  79.             mov   ax, c_seg
  80.             mov   es, ax
  81.             mov   dx, c_off
  82.             mov   ax, 0ch
  83.             mov   cx, EVENT_MASK
  84.  
  85.             int 033h
  86.             }
  87.  
  88.       /* set mouse x, y limits */
  89.       asm   {
  90.             mov   ax, 7
  91.             mov   cx, 0
  92.             mov   dx, 359
  93.  
  94.             int 033h
  95.  
  96.             mov   ax, 8
  97.             mov   cx, 0
  98.             mov   dx, 239
  99.  
  100.             int 033h
  101.  
  102.  
  103.             /* set initial mouse_x, mouse_y */
  104.             mov   ax, 3
  105.             int 033h
  106.  
  107.             mov   mouse_x, cx
  108.             mov   mouse_y, dx
  109.             }   
  110.       }
  111.  
  112.    return(mouse_present);
  113. }
  114.  
  115.  
  116.  
  117. /* ---------------------- set_max_mouse() ------------------ May 19,1993 */
  118. void set_max_mouse(short max_x, short max_y)
  119. {
  120.       /* set mouse x, y limits */
  121.       asm   {
  122.             mov   ax, 7
  123.             mov   cx, 0
  124.             mov   dx, max_x
  125.  
  126.             int 033h
  127.  
  128.             mov   ax, 8
  129.             mov   cx, 0
  130.             mov   dx, max_y
  131.  
  132.             int 033h
  133.             }
  134.  
  135. }
  136.  
  137.  
  138. /* ---------------------- deinit_mouse() ------------------ April 1,1993 */
  139. void deinit_mouse(void)
  140. {
  141.  
  142.    if ( mouse_present )
  143.       {
  144.       /* deinstall our mouse handler by making int 33 never call it */
  145.       asm   {
  146.             mov   ax, 0ch
  147.             xor   cx, cx     /* mask == 0, handler never called */
  148.  
  149.             int 033h
  150.  
  151.             /* reset mouse driver */
  152.             xor   ax, ax
  153.             int   033h
  154.             }
  155.       }
  156. }
  157.  
  158. /*
  159.  
  160. the asm part
  161.  
  162. */
  163.  
  164.  
  165. ;***************************************************************
  166. ;*                                                             *
  167. ;* File: cmousea.asm                                           *
  168. ;*                                                             *
  169. ;* Assembly language hook for CMOUSE library event handler     *
  170. ;* Assemble with /Ml switch                                    *
  171. ;*                                                             *
  172. ;***************************************************************
  173. ; real code for real men
  174. ; adjust for proper memory model
  175. .MODEL SMALL,C
  176.  
  177. .CODE
  178.       PUBLIC mouse_event_func,mouse_int
  179.  
  180. mouse_event_func DD ?
  181.  
  182.  
  183. mouse_int PROC FAR
  184.           PUSHF
  185.           CALL CS:[mouse_event_func]
  186.           RET
  187. mouse_int ENDP
  188.  
  189.           END
  190.